package com.maxmlr.framework.beans;

import com.maxmlr.framework.aop.AopConfig;
import com.maxmlr.framework.aop.AopProxy;
import lombok.Getter;
import lombok.Setter;

/**
 * @ClassName BeanWrapper
 * @Description ioc容器实际操作的对象
 * @Author maxiao
 * @Date 2020/3/13 下午3:17
 * @Version V1.0
 */
public class BeanWrapper {

    private AopProxy aopProxy = new AopProxy();

    private Object wrapperInstance;
    //原始的通过反射new出来，要把包装起来，存下来
    @Getter
    private Object originalInstance;

    @Setter
    private BeanPostProcessor beanPostProcessor;

    public BeanWrapper(Object instance) {
        //从这里开始，我们要把动态的代码添加进来了
        this.wrapperInstance = aopProxy.getProxy(instance);
        this.originalInstance = instance;
    }

    public void setAopConfig(AopConfig config) {
        aopProxy.setConfig(config);
    }

    public Object getWrapperInstance() throws Exception {
//        return AopProxyUtils.getTargetObject(this.wrapperInstance);
        return this.wrapperInstance;
    }
}
